package sistema.web.servlet.responsablefamilia;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import sistema.web.bussiness.IPersonaBussiness;
import sistema.web.bussiness.impls.PersonaBussiness;
import sistema.web.dtos.PersonaDTO;
import sistema.web.dtos.TipoDocumentoDTO;

/**
 * Servlet implementation class RespFamiliaModificar_Servlet
 */
@WebServlet("/RespFamiliaModificar_Servlet")
public class RespFamiliaModificar_Servlet extends HttpServlet {
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RespFamiliaModificar_Servlet() {
        super();
    }

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html;charset=UTF-8");
		
		String codigo = request.getParameter("codigo");
		
		IPersonaBussiness bus = new PersonaBussiness();
		List<PersonaDTO> listPersona = bus.listar("idPersona", codigo);
		
		if(listPersona != null) {
			PersonaDTO dtoPersona = listPersona.get(0);
			
			request.setAttribute("codigo", dtoPersona.getIdPersona());
			request.setAttribute("nombre", dtoPersona.getNombres());
			request.setAttribute("apePaterno", dtoPersona.getApePaterno());
			request.setAttribute("apeMaterno", dtoPersona.getApeMaterno());
			request.setAttribute("sexo", dtoPersona.getSexo());
			request.setAttribute("correo", dtoPersona.getCorreo());
			request.setAttribute("tipoDocumento", dtoPersona.getIdTipoDocumento());
			request.setAttribute("nroDocumento", dtoPersona.getNroDocumento());
			request.setAttribute("celular", dtoPersona.getCelular());
			request.setAttribute("direccion", dtoPersona.getDireccion());
		}
		
		/* -- Carga los tipos de documentos -- */
		List<TipoDocumentoDTO> listTipoDocumento;
		
		listTipoDocumento = bus.obtenerTipoDocumento();
		
		request.setAttribute("listTipoDocumento", listTipoDocumento);
		
		RequestDispatcher rd = request.getRequestDispatcher("/regi_responsable.jsp");
        rd.forward(request, response);
	}
}